package tpo.lmhconsumer.lmhconsumer.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import dto.Dto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.Unit;
import tpo.lmhconsumer.lmhconsumer.service.UnitService;

import java.util.List;
import java.util.Map;

/**
 * 商品单位
 */
@RestController
public class UnitController {
    @Autowired
    UnitService unitService;
    /**
     * @param map
     * @return
     */
    @RequestMapping("getUnit")
    @HystrixCommand(fallbackMethod = "rd_map")
    Dto getUnit(@RequestBody Map map){
        return unitService.getUnit(map);
    }

    /**
     * @param map
     * @return
     */
    @RequestMapping("delUnit")
    @HystrixCommand(fallbackMethod = "rd_map")
    Dto delUnit(@RequestBody Map map){
        return unitService.delUnit(map);
    }

    /**
     * @param map
     * @return
     */
    @RequestMapping("addUnit")
    @HystrixCommand(fallbackMethod = "rd_map")
    Dto addUnit(@RequestBody Map map){
        return unitService.addUnit(map);
    }

    /**
     * @param map
     * @return
     */
    @RequestMapping("updateUnit")
    @HystrixCommand(fallbackMethod = "rd_map")
    Dto updateUnit(@RequestBody Map map){
        return unitService.updateUnit(map);
    }

    private Dto rd_map(Map map){
        Dto dto=new Dto();
        dto.setMsg("熔断");
        return dto;
    }

}
